﻿<%@ WebHandler Language="C#" Class="ZSProblemFeedBack" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class ZSProblemFeedBack : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private uMESReportOracleDAL dal = new uMESReportOracleDAL();
    public void ProcessRequest(HttpContext context)
    {
        //查询问题快反
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetData")
        {
            string sql = @"
SELECT DECODE(pf.type,0,'S',1,'Q',2,'C',3,'D',4,'P') sqcdptype,pf.problemtype,
       e.fullname,pfd.submitdate,
       DECODE(pfd.problemstatus,0,'已提交','已关闭') problemstatus,
       w.workcentername,w2.workcentername resworkcentername,s.shiftname,t.teamname,
       ROUND((SYSDATE - pfd.submitdate) * 24 * 60,2) dualMin
FROM problemfeedbackdetail pfd
LEFT JOIN problemfeedback pf ON pf.problemfeedbackid = pfd.problemfeedbackid
LEFT JOIN employee e ON e.employeeid = pfd.submitemployeeid
LEFT JOIN Sessionvalues sv ON sv.employeeid = pfd.submitemployeeid
LEFT JOIN teamemployee te ON te.employeeid = e.employeeid
LEFT JOIN team t ON t.teamid = te.teamid
LEFT JOIN shift s ON s.shiftid = t.shiftid
LEFT JOIN workcenter w2 ON w2.workcenterid = pf.problemdepartment 
LEFT JOIN Workcenter w ON NVL(s.workcenterid,sv.workcenterid) = w.workcenterid
LEFT JOIN factory f ON f.factoryid = sv.factoryid
WHERE pfd.problemstatus = 0 
";
            if (context.Request.Form["workcenterid"] != null && context.Request.Form["workcenterid"] != "")
            {
                sql += string.Format(" AND w2.workcenterid = '{0}'", context.Request.Form["workcenterid"].ToString());
            }

            if (context.Request.Form["factoryid"] != null && context.Request.Form["factoryid"] != "")
            {
                sql += string.Format(" AND sv.factoryid = '{0}'", EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"]));
            }

            DataTable dt = dal.GetDataTable(sql);

            foreach (DataColumn col in dt.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }

            var json = JsonConvert.SerializeObject(dt);

            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + dt.Rows.Count
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}